﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace KABS_Commander
{
    public partial class KABS_Commander : Form
    {
        private void decodeIniReadBytes(byte[] data, int count, List<string> list)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < count; i++)
            {
                if (data[i] == '\0')
                {
                    string s = sb.ToString();
                    list.Add(s);
                    sb.Clear();
                }
                else
                {
                    sb.Append((char)data[i]);
                }
            }
        }

        private void readIniLines(string filename, List<string> lines)
        {
            StreamReader sr = null;

            try
            {
                sr = new StreamReader(filename);
                string s;
                while ((s = sr.ReadLine()) != null)
                {
                    s = s.TrimEnd(null);
                    lines.Add(s);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error happened openning " + filename + e.ToString());
            }

            sr.Close();
        }

        private void writeIniLines(string filename, List<string> lines)
        {
            StreamWriter sw = null;

            try
            {
                sw = new StreamWriter(filename, false); // overwrite
                foreach (string s in lines)
                {
                    sw.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error happened openning " + filename + e.ToString());
            }

            sw.Close();
        }

        private void removeIniEqualMark(string filename)
        {
            List<string> data = new List<string>();

            readIniLines(filename, data);

            for (int i = 0; i < data.Count; i++)
            {
                data[i] = data[i].Replace("=", "");
            }

            writeIniLines(filename, data);
        }

    }
}